<?php
namespace app\admin\controller;
use \think\Request;
use think\Db;
use app\common\model\Character as CharacterModel;
use app\common\model\Heo as HeoModel;
use app\common\model\Reason as ReasonModel;
use app\common\model\Apparel as ApparelModel;
use app\common\model\Other as OtherModel;
use app\common\model\Stray as StrayModel;
use app\common\model\Care as CareModel;
use app\common\model\Cohabit as CohabitModel;
use app\common\model\Environment as EnvironmentModel;
use app\common\model\House as HouseModel;
use app\common\model\Adopt as AdoptModel;
class Configure extends \app\admin\controller\Base {
    protected $res = array(
        'character'   => array('css' => '2,3,4', 'js' => 'list'),
        'heo'   => array('css' => '2,3,4', 'js' => 'list'),
        'reason'   => array('css' => '2,3,4', 'js' => 'list'),
        'apparel'   => array('css' => '2,3,4', 'js' => 'list'),
        'other'   => array('css' => '2,3,4', 'js' => 'list'),
        'stray'   => array('css' => '2,3,4', 'js' => 'list'),
        'care'   => array('css' => '2,3,4', 'js' => 'list'),
        'cohabit'   => array('css' => '2,3,4', 'js' => 'list'),
        'environment'   => array('css' => '2,3,4', 'js' => 'list'),
        'house'   => array('css' => '2,3,4', 'js' => 'list'),
        'adopt'   => array('css' => '2,3,4', 'js' => 'list'),
        'report'   => array('css' => '2,3,4', 'js' => 'list'),
    );

    /***
     * 狗的性格
     */
    public function character(){
        $CharacterModel = new CharacterModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $CharacterModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除狗的性格
     */
    public function DelConfigure(){
        $ids = strtoarray(input('post.ids'));
        $CharacterModel = new CharacterModel;
        $where['uco_id'] = array('In', $ids);
        $result = $CharacterModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * 编辑狗性格页面
     */
    public function saveConfigure(){
        $CharacterModel = new CharacterModel;
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $uco_character = input('post.uco_character');
            if($id!=''){//证明是编辑
                $whereS['uco_character'] = $uco_character;
                $result = $CharacterModel->selectOne($whereS);
                if($result['uco_id']!=''){
                    return $this->api_dbError("不能重复添加狗的性格");
                }else{
                    $whereMap['uco_id'] = $id;
                    $data['uco_character'] =$uco_character;
                    $res = $CharacterModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['uco_character'] = $uco_character;
                $result = $CharacterModel->selectOne($whereS);
                if($result['uco_id']!=''){
                    return $this->api_dbError("不能重复添加狗的性格");
                }else{
                    $data['uco_character'] = $uco_character;
                    $res = $CharacterModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['uco_id'] = $id;
            $list = $CharacterModel->selectOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }

    /**
     * @return mixed
     * 互助类别
     */
    public function heo(){
        $HeoModel = new HeoModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $HeoModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除互助类别
     */
    public function delHeo(){
        $ids = strtoarray(input('post.ids'));
        $HeoModel = new HeoModel();
        $where['heo_id'] = array('In', $ids);
        $result = $HeoModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 添加编辑
     */
    public function saveHeo(){
        $HeoModel = new HeoModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $heo_name = input('post.heo_name');
            if($id!=''){//证明是编辑
                $whereS['heo_name'] = $heo_name;
                $result = $HeoModel->getOne($whereS);
                if($result['heo_id']!=''){
                    return $this->api_dbError("不能重复添加互助类别");
                }else{
                    $whereMap['heo_id'] = $id;
                    $data['heo_name'] =$heo_name;
                    $res = $HeoModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['heo_name'] = $heo_name;
                $result = $HeoModel->getOne($whereS);
                if($result['heo_id']!=''){
                    return $this->api_dbError("不能重复添加互助类别");
                }else{
                    $data['heo_name'] = $heo_name;
                    $res = $HeoModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['heo_id'] = $id;
            $list = $HeoModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }

    /***
     * @return mixed
     * 寻狗中狗的失踪原因
     */
    public function reason(){
        $ReasonModel = new ReasonModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $ReasonModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除失踪原因
     */
    public function delReason(){
        $ids = strtoarray(input('post.ids'));
        $ReasonModel = new ReasonModel();
        $where['reason_id'] = array('In', $ids);
        $result = $ReasonModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 失踪原因添加编辑
     */
    public function saveReason(){
        $ReasonModel = new ReasonModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.reason_name');
            if($id!=''){//证明是编辑
                $whereS['reason_name'] = $reason_name;
                $result = $ReasonModel->getOne($whereS);
                if($result['reason_id']!=''){
                    return $this->api_dbError("不能重复添加失踪原因");
                }else{
                    $whereMap['reason_id'] = $id;
                    $data['reason_name'] =$reason_name;
                    $res = $ReasonModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['reason_name'] = $reason_name;
                $result = $ReasonModel->getOne($whereS);
                if($result['reason_id']!=''){
                    return $this->api_dbError("不能重复添加失踪原因");
                }else{
                    $data['reason_name'] = $reason_name;
                    $res = $ReasonModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['reason_id'] = $id;
            $list = $ReasonModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 丢失的狗狗的穿戴的特征
     */
    public function apparel(){
        $ApparelModel = new ApparelModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $ApparelModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除丢失的狗狗的穿戴的特征
     */
    public function delApparel(){
        $ids = strtoarray(input('post.ids'));
        $ApparelModel = new ApparelModel();
        $where['udskca_id'] = array('In', $ids);
        $result = $ApparelModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 丢失的狗狗的穿戴的特征添加编辑
     */
    public function saveApparel(){
        $ApparelModel = new ApparelModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.udskca_name');
            if($id!=''){//证明是编辑
                $whereS['udskca_name'] = $reason_name;
                $result = $ApparelModel->getOne($whereS);
                if($result['udskca_id']!=''){
                    return $this->api_dbError("不能重复添加狗狗的穿戴的特征");
                }else{
                    $whereMap['udskca_id'] = $id;
                    $data['udskca_name'] =$reason_name;
                    $res = $ApparelModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['udskca_name'] = $reason_name;
                $result = $ApparelModel->getOne($whereS);
                if($result['udskca_id']!=''){
                    return $this->api_dbError("不能重复添加狗狗的穿戴的特征");
                }else{
                    $data['udskca_name'] = $reason_name;
                    $res = $ApparelModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['udskca_id'] = $id;
            $list = $ApparelModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 丢失的狗狗的穿戴的特征
     */
    public function other(){
        $OtherModel = new OtherModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $OtherModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除丢失的狗狗的穿戴的特征
     */
    public function delOther(){
        $ids = strtoarray(input('post.ids'));
        $OtherModel = new OtherModel();
        $where['udsci_id'] = array('In', $ids);
        $result = $OtherModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 丢失的狗狗的穿戴的特征添加编辑
     */
    public function saveOther(){
        $OtherModel = new OtherModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.udsci_name');
            if($id!=''){//证明是编辑
                $whereS['udsci_name'] = $reason_name;
                $result = $OtherModel->getOne($whereS);
                if($result['udsci_id']!=''){
                    return $this->api_dbError("不能重复添加丢失狗的其他特征");
                }else{
                    $whereMap['udsci_id'] = $id;
                    $data['udsci_name'] =$reason_name;
                    $res = $OtherModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['udsci_name'] = $reason_name;
                $result = $OtherModel->getOne($whereS);
                if($result['udsci_id']!=''){
                    return $this->api_dbError("不能重复添加丢失狗的其他特征");
                }else{
                    $data['udsci_name'] = $reason_name;
                    $res = $OtherModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['udsci_id'] = $id;
            $list = $OtherModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }



    /***
     * @return mixed
     * 流浪狗的特征
     */
    public function stray(){
        $StrayModel = new StrayModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $StrayModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除流浪狗的特征
     */
    public function delStray(){
        $ids = strtoarray(input('post.ids'));
        $StrayModel = new StrayModel();
        $where['udsc_id'] = array('In', $ids);
        $result = $StrayModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 流浪狗的特征添加编辑
     */
    public function saveStray(){
        $StrayModel = new StrayModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.udsc_name');
            if($id!=''){//证明是编辑
                $whereS['udsc_name'] = $reason_name;
                $result = $StrayModel->getOne($whereS);
                if($result['udsc_id']!=''){
                    return $this->api_dbError("不能重复添加流浪狗特征");
                }else{
                    $whereMap['udsc_id'] = $id;
                    $data['udsc_name'] =$reason_name;
                    $res = $StrayModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['udsc_name'] = $reason_name;
                $result = $StrayModel->getOne($whereS);
                if($result['udsc_id']!=''){
                    return $this->api_dbError("不能重复添加流浪狗特征");
                }else{
                    $data['udsc_name'] = $reason_name;
                    $res = $StrayModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['udsc_id'] = $id;
            $list = $StrayModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 领养后照顾人配置表
     */
    public function care(){
        $CareModel = new CareModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $CareModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除流领养后照顾人配置表
     */
    public function delCare(){
        $ids = strtoarray(input('post.ids'));
        $CareModel = new CareModel();
        $where['care_id'] = array('In', $ids);
        $result = $CareModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养后照顾人配置表添加编辑
     */
    public function saveCare(){
        $CareModel = new CareModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.care_name');
            if($id!=''){//证明是编辑
                $whereS['care_name'] = $reason_name;
                $result = $CareModel->getOne($whereS);
                if($result['care_id']!=''){
                    return $this->api_dbError("不能重复添加领养后照顾人");
                }else{
                    $whereMap['care_id'] = $id;
                    $data['care_name'] =$reason_name;
                    $res = $CareModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['care_name'] = $reason_name;
                $result = $CareModel->getOne($whereS);
                if($result['care_id']!=''){
                    return $this->api_dbError("不能重复添加领养后照顾人");
                }else{
                    $data['care_name'] = $reason_name;
                    $res = $CareModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['care_id'] = $id;
            $list = $CareModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 领养主人同住人员配置表
     */
    public function cohabit(){
        $CohabitModel = new CohabitModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $CohabitModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除领养主人同住人员配置表
     */
    public function delCohabit(){
        $ids = strtoarray(input('post.ids'));
        $CohabitModel = new CohabitModel();
        $where['cohabit_id'] = array('In', $ids);
        $result = $CohabitModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养主人同住人员配置表添加编辑
     */
    public function saveCohabit(){
        $CohabitModel = new CohabitModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.cohabit_name');
            if($id!=''){//证明是编辑
                $whereS['cohabit_name'] = $reason_name;
                $result = $CohabitModel->getOne($whereS);
                if($result['cohabit_id']!=''){
                    return $this->api_dbError("不能重复添加领养主人同住人员");
                }else{
                    $whereMap['cohabit_id'] = $id;
                    $data['cohabit_name'] =$reason_name;
                    $res = $CohabitModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['cohabit_name'] = $reason_name;
                $result = $CohabitModel->getOne($whereS);
                if($result['cohabit_id']!=''){
                    return $this->api_dbError("不能重复添加领养主人同住人员");
                }else{
                    $data['cohabit_name'] = $reason_name;
                    $res = $CohabitModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['cohabit_id'] = $id;
            $list = $CohabitModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }

    /***
     * @return mixed
     * 领养人居住环境
     */
    public function environment(){
        $EnvironmentModel = new EnvironmentModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $EnvironmentModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除领养人居住环境
     */
    public function delEnvironment(){
        $ids = strtoarray(input('post.ids'));
        $EnvironmentModel = new EnvironmentModel();
        $where['environment_id'] = array('In', $ids);
        $result = $EnvironmentModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养人居住环境添加编辑
     */
    public function saveEnvironment(){
        $EnvironmentModel = new EnvironmentModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.environment_name');
            if($id!=''){//证明是编辑
                $whereS['environment_name'] = $reason_name;
                $result = $EnvironmentModel->getOne($whereS);
                if($result['environment_id']!=''){
                    return $this->api_dbError("不能重复添加领养人居住环境");
                }else{
                    $whereMap['environment_id'] = $id;
                    $data['environment_name'] =$reason_name;
                    $res = $EnvironmentModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['environment_name'] = $reason_name;
                $result = $EnvironmentModel->getOne($whereS);
                if($result['environment_id']!=''){
                    return $this->api_dbError("不能重复添加领养人居住环境");
                }else{
                    $data['environment_name'] = $reason_name;
                    $res = $EnvironmentModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['environment_id'] = $id;
            $list = $EnvironmentModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 领养人居住房子属于人
     */
    public function house(){
        $HouseModel = new HouseModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $HouseModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除领养人居住房子属于人
     */
    public function delHouse(){
        $ids = strtoarray(input('post.ids'));
        $HouseModel = new HouseModel();
        $where['house_id'] = array('In', $ids);
        $result = $HouseModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养人居住房子属于人添加编辑
     */
    public function saveHouse(){
        $HouseModel = new HouseModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.house_name');
            if($id!=''){//证明是编辑
                $whereS['house_name'] = $reason_name;
                $result = $HouseModel->getOne($whereS);
                if($result['house_id']!=''){
                    return $this->api_dbError("不能重复添加领养人居住房子属于人");
                }else{
                    $whereMap['house_id'] = $id;
                    $data['house_name'] =$reason_name;
                    $res = $HouseModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['house_name'] = $reason_name;
                $result = $HouseModel->getOne($whereS);
                if($result['house_id']!=''){
                    return $this->api_dbError("不能重复添加领养人居住房子属于人");
                }else{
                    $data['house_name'] = $reason_name;
                    $res = $HouseModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['house_id'] = $id;
            $list = $HouseModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }


    /***
     * @return mixed
     * 领养人居住房子属于人
     */
    public function adopt(){
        $AdoptModel = new AdoptModel();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = $AdoptModel->relData(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除领养人居住房子属于人
     */
    public function delAdopt(){
        $ids = strtoarray(input('post.ids'));
        $AdoptModel = new AdoptModel();
        $where['reason_id'] = array('In', $ids);
        $result = $AdoptModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养人居住房子属于人添加编辑
     */
    public function saveAdopt(){
        $AdoptModel = new AdoptModel();
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.reason_name');
            if($id!=''){//证明是编辑
                $whereS['reason_name'] = $reason_name;
                $result = $AdoptModel->getOne($whereS);
                if($result['reason_id']!=''){
                    return $this->api_dbError("不能重复添加领养原因");
                }else{
                    $whereMap['reason_id'] = $id;
                    $data['reason_name'] =$reason_name;
                    $res = $AdoptModel->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['reason_name'] = $reason_name;
                $result = $AdoptModel->getOne($whereS);
                if($result['reason_id']!=''){
                    return $this->api_dbError("不能重复添加领养原因");
                }else{
                    $data['reason_name'] = $reason_name;
                    $res = $AdoptModel->save($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['reason_id'] = $id;
            $list = $AdoptModel->getOne($where);
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }

    /**
     * @return mixed
     * 举报类型
     */
    public function report(){
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $page = input('get.page');
        $list = Db::table('up_report_name')->paginate(15);
        $this->assign(
            array(
                'list'=>$list,
                'action'=>$action,
                'page'=>$page,
            )
        );
        return $this->fetch();
    }

    /**
     * @return \think\response\Json
     * 删除领养人居住房子属于人
     */
    public function delReport(){
        $ids = strtoarray(input('post.ids'));
        $where['report_type_id'] = array('In', $ids);
        $result = Db::table('up_report_name')->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }

    /**
     * @return \think\response\Json
     * 领养人居住房子属于人添加编辑
     */
    public function saveReport(){
        if(Request::instance()->isPost()){
            $id = input('post.id');
            $reason_name = input('post.report_name');
            if($id!=''){//证明是编辑
                $whereS['report_name'] = $reason_name;
                $whereS['report_type_id'] =array('NEQ',$id);
                $result = Db::table('up_report_name')->where($whereS)->find();
                if($result['report_type_id']!=''){
                    return $this->api_dbError("不能重复添加举报原因");
                }else{
                    $whereMap['report_type_id'] = $id;
                    $data['report_name'] =$reason_name;
                    $res = Db::table('up_report_name')->where($whereMap)->update($data);
                }
            }else{//添加
                $whereS['report_name'] = $reason_name;
                $result = Db::table('up_report_name')->where($whereS)->find();

                if($result['report_type_id']!=''){
                    return $this->api_dbError("不能重复添加举报原因");
                }else{
                    $data['report_name'] = $reason_name;
                    $res = Db::table('up_report_name')->insertGetId($data);
                }
            }
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $id = input('get.id');
        if($id!=''){
            $where['report_type_id'] = $id;
            $list = Db::table('up_report_name')->where($where)->find();
            $this->assign('id', $id);
            $this->assign('ad', $list);
        }
        return $this->fetch();
    }
}